package com.ag.wsq.service.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.ag.bean.TbDetailShift;
import com.ag.bean.TbDuty;
import com.ag.bean.TbSched;
import com.ag.bean.TbShiftType;
import com.ag.bean.TbUser;
import com.ag.bean.TbWorkDay;
import com.ag.common.AgException;
import com.ag.common.IBaseService;
import com.ag.common.IDUtil;
import com.ag.dao.TbDutyDAO;
import com.ag.dao.TbShiftTypeDAO;
import com.ag.dao.TbUserDAO;
import com.ag.dao.TbWorkDayDAO;
import com.ag.wsq.dao.DetailShiftDAO;
import com.ag.wsq.dao.SchedDAO;

public class SchedBaseServiceImpl implements IBaseService<TbSched, String> {
	
	private static Logger logger = Logger.getLogger(SchedBaseServiceImpl.class);
	
	private SchedDAO schedDAO;
	private TbUserDAO userDAO;
	private DetailShiftDAO detailShiftDAO;
	private TbDutyDAO dutyDAO;
	private TbWorkDayDAO workDayDAO;
	private TbShiftTypeDAO shiftTypeDAO;
	/**
	 * 查找值班的基础数据
	 * 
	 */
	public List<TbUser> getAllUser() {
		logger.info("findAll user ");
		return this.userDAO.findAll();
	}
	
	public List<TbDetailShift> getAllDShift(){
		logger.info("findAll detailShift");
		return this.detailShiftDAO.findAll();
	}
	
	public List<TbDuty> getAllDuty(){
		logger.info("findAll duty");
		return this.dutyDAO.findAll();
	}

	public List<TbWorkDay> getAllWDay(){
		logger.info("findAll WDay");
		return this.workDayDAO.findAll();
	}
	
	public List<TbShiftType> getAllSType(){
		logger.info("findAll SType");
		return this.shiftTypeDAO.findAll();
	}
	/**
	 * 获取对应岗位的所有班次
	 * 
	 */
	public List<TbDetailShift> getDShift(String duId){
		logger.info("findAll detailShift to duty");		
		return this.detailShiftDAO.getDShiftById(duId);
	}	
	/**
	 * 通过ID返回该实体对象
	 * 
	 */
	public TbDuty findDutyById(String duId){
		return this.dutyDAO.findById(duId);
	}
	
	public TbWorkDay findWDayById(String wdId){
		logger.info("findWDayById satrt---");
		return this.workDayDAO.findById(wdId);
	}
	
	public TbShiftType findSTypeById(String psId){
		return this.shiftTypeDAO.findById(psId);
	}
	
	public TbUser findUserById(String UId){
		return this.userDAO.findById(UId);
	}
	
	public TbDetailShift findDShiftById(String dsId){
		return this.detailShiftDAO.findById(dsId);
	}
	/**
	 * 保存基础数据
	 * 
	 */
	public void saveOrUpdateDuty(TbDuty duty){
		dutyDAO.attachDirty(duty);
	}
	
	public void saveOrUpdateSched(TbSched sched){
		schedDAO.attachDirty(sched);
	}
	/**
	 * 删除岗位
	 * 
	 */
	public boolean delete(String id) {
		try {
			TbDuty duty = dutyDAO.findById(id);
			duty.setA(IDUtil.DELETE);
			dutyDAO.attachDirty(duty);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new AgException("删除角色失败！", e);
		}
	}

	public boolean delete(TbSched t) {
		return false;
	}

	public TbSched findById(String id) {
		return null;
	}

	public boolean save(TbSched t) {
		return false;
	}

	public boolean update(TbSched t) {
		return false;
	}

	public TbUserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(TbUserDAO userDAO) {
		this.userDAO = userDAO;
	}

	public TbDutyDAO getDutyDAO() {
		return dutyDAO;
	}

	public void setDutyDAO(TbDutyDAO dutyDAO) {
		this.dutyDAO = dutyDAO;
	}


	public TbWorkDayDAO getWorkDayDAO() {
		return workDayDAO;
	}

	public void setWorkDayDAO(TbWorkDayDAO workDayDAO) {
		this.workDayDAO = workDayDAO;
	}

	public TbShiftTypeDAO getShiftTypeDAO() {
		return shiftTypeDAO;
	}

	public void setShiftTypeDAO(TbShiftTypeDAO shiftTypeDAO) {
		this.shiftTypeDAO = shiftTypeDAO;
	}

	public SchedDAO getSchedDAO() {
		return schedDAO;
	}

	public void setSchedDAO(SchedDAO schedDAO) {
		this.schedDAO = schedDAO;
	}

	public DetailShiftDAO getDetailShiftDAO() {
		return detailShiftDAO;
	}

	public void setDetailShiftDAO(DetailShiftDAO detailShiftDAO) {
		this.detailShiftDAO = detailShiftDAO;
	}

}
